package com.mine;

import java.util.ArrayList;
import java.util.List;

/**
 * 寻找素数
 *
 * @author wangtonggui
 * @version 1.0.0
 * @since 2022/03/24 18:53
 */
public class PrimeNumber {
  public static void main(String[] args) {
    System.out.println(getPrimes(10));
  }

  public static List<Integer> getPrimes(int n) {
    List<Integer> list = new ArrayList<>();
    for (int i = 3; i < n; i++) {
      if (isPrime(i)) {
        list.add(i);
      }
    }
    return list;
  }

  private static boolean isPrime(int n) {
    for (int i = 2; i <= n / 2; i++) {
      if (n % i == 0) {
        return false;
      }
    }
    return true;
  }
}
